<?php

namespace RedMVC;

/**
 * Feed class
 *
 * @category    RedMVC
 * @author      Jan Fischer, bitWorking <info@bitworking.de>
 */
class Feed{

    public $title;
    public $description;
    public $link;
    public $linkSelf;
    public $date;
    public $author;
    public $language;

    protected $_entries;

    /**
     * add feed entry to feed
     *
     * @param Feed\Entry $entry
     */
    public function addEntry(Feed\Entry $entry){
        $this->_entries[] = $entry;
    }

    /**
     * return all entries
     *
     * @return array  Feed\Entry objects
     */
    public function getEntries(){
        return $this->_entries;
    }

    /**
     * alias for toAtom
     *
     * @return string
     */
    public function __toString(){
        return $this->toAtom();
    }

    /**
     * build Feed object from newsfeed url
     *
     * @param string $url
     * @param int $timeout
     * @param int $method (see File constants)
     * @return Feed
     */
    public static function fromUrl($url, $timeout = 10, $method = File::REMOTE_DATA_METHOD_CURL){
        return Feed\Reader::getFeed($url, $timeout, $method);
    }

    /**
     * convert this Feed to Atom format
     *
     * @return string
     */
    public function toAtom(){
        return Feed\Writer::getXml($this, Feed\Writer::FEED_TYPE_ATOM_10);
    }

    /**
     * convert this Feed to RSS 0.9 format
     *
     * @return string
     */
    public function toRss09(){
        return Feed\Writer::getXml($this, Feed\Writer::FEED_TYPE_RSS_09);
    }

    /**
     * convert this Feed to RSS 2.0 format
     *
     * @return string
     */
    public function toRss20(){
        return Feed\Writer::getXml($this, Feed\Writer::FEED_TYPE_RSS_20);
    }

}